/* the example on page 80 */

#include <gtk/gtk.h>
/* 准备材料，自定义函数  */
	/*  comments注释  */

/* 程序主体 */
int main( int argc, char *argv[] )
{
	GtkWidget *window;
	/* 声明变量window为构件gtkwidget */
	GtkWidget *vbox;
	GtkWidget *toolbar;
	GtkWidget *newimage;
	GtkWidget *openimage;
	GtkWidget *saveimage;
	GtkWidget *saveasimage;
	GtkWidget *quitimage;
	GtkWidget *new;
	/* 声明变量new为GtkToolItem类型 */
	GtkToolItem *open;
	GtkToolItem *save;
	GtkToolItem *saveas;
	GtkToolItem *quit;
	GtkToolItem *separator;
	GtkToolItem *copy;
	GtkToolItem *cut;
	GtkToolItem *paste;
	GtkToolItem *find;
	GtkToolItem *replace;
	GtkToolItem *helpf1;
	GtkToolItem *aboutf7;
	
	gtk_init (&argc, &argv);
	/* 初始化gtk */

	window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
	/*  创建顶级窗口 */
	gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
	/*  设置窗口位置为显示器的中间 */
	gtk_window_set_default_size(GTK_WINDOW(window), 1000, 200);
	/*  设置窗口的大小，横为1000像素，竖为200像素 */
	gtk_window_set_title (GTK_WINDOW (window), "测试toolbar");
	/*  为窗口顶部加上标题为测试toolbar  */
	g_signal_connect (G_OBJECT (window), "destroy", G_CALLBACK (gtk_main_quit), NULL);
	/*  为窗口加上动作，当收到destroy信号，就启动gtk_main_quit事件，gtk_main_quit就是鼠标单击窗口右上角的关闭按钮就终止程序  */
	gtk_container_set_border_width (GTK_CONTAINER (window), 0);
	/*  简单的理解是将窗口变成容器，可以装入其它构件，构件边缘与窗口边缘的距离为0像数  */
	
	vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
	/*  创建组合框  */
	gtk_container_add (GTK_CONTAINER(window), vbox);
	/*  将组合框装入窗口容器  */
	
	toolbar = gtk_toolbar_new ();
	/*  创建工具条  */
	gtk_toolbar_set_style (GTK_TOOLBAR (toolbar), GTK_TOOLBAR_BOTH); 
	/*  设置工具条要同时显示图标和文字  */
	gtk_box_pack_start (GTK_BOX(vbox), toolbar, FALSE, FALSE, 0);
	/*  将工具条装入组合框容器  */
	
	newimage = gtk_image_new_from_file ("/usr/share/icons/gnome/32x32/actions/document-new.png");
	/*  从文件读取图片  */
	new = gtk_tool_button_new (newimage, "新建");
	/*  创建工具条按钮，使用图片newimage和“新建”文字  */
	gtk_toolbar_insert (GTK_TOOLBAR(toolbar), new, -1);
	/*  将新建工具条按钮加入到工具条中，-1表示从后面加入  */
	
	openimage = gtk_image_new_from_file ("/usr/share/icons/gnome/32x32/actions/document-open.png");
	open = gtk_tool_button_new (openimage, "打开");
	gtk_toolbar_insert (GTK_TOOLBAR(toolbar), open, -1);
	
	saveimage = gtk_image_new_from_file ("/usr/share/icons/gnome/32x32/actions/document-save.png");
	save = gtk_tool_button_new (saveimage, "保存");
	gtk_toolbar_insert (GTK_TOOLBAR(toolbar), save, -1);
	
	saveasimage = gtk_image_new_from_file ("/usr/share/icons/gnome/32x32/actions/document-save-as.png");
	saveas = gtk_tool_button_new (saveasimage, "另存为");
	gtk_toolbar_insert (GTK_TOOLBAR(toolbar), saveas, -1);
	
	quitimage = gtk_image_new_from_file ("/usr/share/icons/gnome/32x32/actions/application-exit.png");
	quit = gtk_tool_button_new (quitimage, "退出");
	gtk_toolbar_insert (GTK_TOOLBAR(toolbar), quit, -1);

	separator = gtk_separator_tool_item_new ();
	/*  创建工具条分隔条  */
	gtk_toolbar_insert (GTK_TOOLBAR(toolbar), separator, -1);
	/*  将新建工具条分隔条加入到工具条中，-1表示从后面加入  */
	
	copy = gtk_tool_button_new (NULL, "复制");
	/*  创建工具条按钮，不使用图片，使用“复制”文字  */
	gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON(copy), "edit-copy");
	/*  从系统自带图标库中指定edit-copy图片作为工具条按钮的图片  */
	gtk_toolbar_insert (GTK_TOOLBAR(toolbar), copy, -1);
	
	cut = gtk_tool_button_new (NULL, "剪切");
	gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON(cut), "edit-cut");
	gtk_toolbar_insert (GTK_TOOLBAR(toolbar), cut, -1);
	
	paste = gtk_tool_button_new (NULL, "粘贴");
	gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON(paste), "edit-paste");
	gtk_toolbar_insert (GTK_TOOLBAR(toolbar), paste, -1);
	
	find = gtk_tool_button_new (NULL, "查找");
	gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON(find), "edit-find");
	gtk_toolbar_insert (GTK_TOOLBAR(toolbar), find, -1);
	
	replace = gtk_tool_button_new (NULL, "替换");
	gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON(replace), "edit-find-replace");
	gtk_toolbar_insert (GTK_TOOLBAR(toolbar), replace, -1);

	separator = gtk_separator_tool_item_new ();
	gtk_toolbar_insert (GTK_TOOLBAR(toolbar), separator, -1);
	
	helpf1 = gtk_tool_button_new (NULL, NULL);
	/*  创建工具条按钮，不带有图片，不带有文字  */
	gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON(helpf1), "gtk-help");
	/*  从系统自带图标库中指定gtk-help图片作为工具条按钮的图片  */
	gtk_toolbar_insert (GTK_TOOLBAR(toolbar), helpf1, -1);
	
	aboutf7 = gtk_tool_button_new (NULL, NULL);
	gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON(aboutf7), "gtk-about");
	gtk_toolbar_insert (GTK_TOOLBAR(toolbar), aboutf7, -1);
	
	
	gtk_widget_show_all (window);
	/*  显示构件窗口包括所有构件  */
	gtk_main ();
	/*  进入主循环，等待信号（鼠标键盘）输入  */
	return 0;
}
/* gcc pageXX.c -o pageXX `pkg-config --cflags --libs gtk+-3.0` */
